/*
 * Copyright (c) 2025 CAX Conversion Project
 */
package com.comac.ins.bomt.domain.vo;

import com.alibaba.excel.annotation.ExcelProperty;
import com.comac.ins.common.core.exception.BizException;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Field;

/**
 * 强度数模清单导入
 *
 * @author zhanghongyi
 * @date 2024 /8/26
 * @description DetailStrengthBomImportVo
 */
@Data
public class DetailStrengthBomImportVo {
    /**
     * 层级
     */
    @ExcelProperty(value = "层级")
    private String level;
    /**
     * 图号
     */
    @ExcelProperty(value = "图号")
    private String code;
    /**
     * 名称
     */
    @ExcelProperty(value = "名称")
    private String name;
    @ExcelProperty(index = 3)
    private String a;
    @ExcelProperty(index = 4)
    private String b;
    @ExcelProperty(index = 5)
    private String c;
    @ExcelProperty(index = 6)
    private String d;
    @ExcelProperty(index = 7)
    private String e;
    @ExcelProperty(index = 8)
    private String f;
    @ExcelProperty(index = 9)
    private String g;
    @ExcelProperty(index = 10)
    private String h;
    @ExcelProperty(index = 11)
    private String i;
    @ExcelProperty(index = 12)
    private String j;
    @ExcelProperty(index = 13)
    private String k;
    @ExcelProperty(index = 14)
    private String l;
    @ExcelProperty(index = 15)
    private String m;
    @ExcelProperty(index = 16)
    private String n;
    @ExcelProperty(index = 17)
    private String o;
    @ExcelProperty(index = 18)
    private String p;
    @ExcelProperty(index = 19)
    private String q;
    @ExcelProperty(index = 20)
    private String r;
    @ExcelProperty(index = 21)
    private String s;
    @ExcelProperty(index = 22)
    private String t;
    @ExcelProperty(index = 23)
    private String u;
    @ExcelProperty(index = 24)
    private String v;
    @ExcelProperty(index = 25)
    private String w;
    @ExcelProperty(index = 26)
    private String x;
    @ExcelProperty(index = 27)
    private String y;
    @ExcelProperty(index = 28)
    private String z;

    /**
     * 获取版本和版本数
     *
     * @return Pair<版本 ， 版本数>
     */
    public Pair<String, String> getVersionAndNum() {
        for (char c = 'a'; c <= 'z'; ++c) {
            try {
                Field field = this.getClass().getDeclaredField(String.valueOf(c));
                ReflectionUtils.makeAccessible(field);
                String v = (String) ReflectionUtils.getField(field, this);
                if (StringUtils.isNotBlank(v)) {
                    return Pair.of(String.valueOf(c).toUpperCase(), v);
                }
            } catch (NoSuchFieldException e) {
                throw new BizException("parse strength bom fail:" + e.getMessage());
            }

        }
        return Pair.of(null, null);
    }
}
